using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using SCBK.Api.Model;
using SCBK.Api.Repository;



namespace ShoppingCenter.Backend.Api.Controllers
{
    // [Authorize]
    [ApiController]
    [Route("[controller]")]
    public class UsersController : ControllerBase
    {
        private IConfiguration _configuration;
        //初始化token
        // private TokenParameter _toKenParameter;

        private IRepository<User> _usersRepository;

        public UsersController(IConfiguration configuration, IRepository<User> usersRepository)
        {
            _configuration = configuration;
            _usersRepository = usersRepository;
        }


        // //登录获取token
        // [AllowAnonymous]
        // [HttpPost, Route("token")]
        // public dynamic GetToken(CURUser newUser)
        // {
        //     var username = newUser.Username.Trim();
        //     var password = newUser.Password.Trim();

        //     var user =
        //         _usersRepository
        //             .Table
        //             .Where(x =>
        //                 x.Username == username && x.Password == password)
        //             .FirstOrDefault();


        //     if (user == null)
        //     {
        //         return new
        //         {
        //             Code = 104,
        //             Data = "",
        //             Msg = "用户名或密码不正确，请确认后重试"
        //         };
        //     }

        //     var token = ToKenHelper.GenerateToekn(_toKenParameter, user.Username);
        //     var refreshToken = "112358";

        //     return new
        //     {
        //         Code = 1000,
        //         Data = new { Token = token, refreshToken = refreshToken, user },
        //         Msg = "用户登录成功^_^"
        //     };
        // }


        //获取所有用户
        public dynamic Get()
        {
            var users = _usersRepository.Table.ToList();

            return new
            {
                Code = 1000,
                Data = users,
                Msg = "获取所有用户成功"
            };
        }
    }
}